local shuguo = fk.CreateSkill{
  name = "doublez__shuguo"
}

Fk:loadTranslationTable{
  ["doublez__shuguo"] = "疏国",
  [":doublez__shuguo"] = "出牌阶段限一次，你可以依次用牌堆底的牌与一名其他角色拼点三次，每次赢的角色使用一张拼点牌，若不为其，下次改为其用牌堆底的牌与你拼点。",

  ["#doublez__shuguo-use"] = "疏国：请使用一张拼点牌",

  ["$doublez__shuguo"] = "夫国之有民，犹水之有舟，停则以安，扰则以危。",
}

shuguo:addEffect("active", {
  max_phase_use_time = 1,
  card_filter = Util.FalseFunc,
  target_filter = function (self, player, to_select, selected, selected_cards, card, extra_data)
    return to_select:getHandcardNum() > 0 and #selected == 0 and to_select ~= player
  end,
  feasible = function (self, player, selected, selected_cards, card)
    return #selected > 0 
  end,
  on_use = function (self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    local fromPlayer = true
    local pindian
    local user
    for i = 1,3,1 do
      local use_card = Fk:getCardById(room:getNCards(1, "bottom")[1])
      if fromPlayer then
        if target:getHandcardNum() == 0 then return end
        pindian = player:pindian({target}, shuguo.name, use_card)
        user = pindian.results[target].winner
      else
        if player:getHandcardNum() == 0 then return end
        pindian = target:pindian({player}, shuguo.name, use_card)
        user = pindian.results[player].winner
      end
      if user then
        local ids = {}
        for _, card in ipairs({pindian.fromCard, pindian.results[fromPlayer and target or player].toCard}) do
          if room:getCardArea(card) == Card.DiscardPile then
            table.insertIfNeed(ids, card:getEffectiveId())
          end
        end
        ids = table.filter(ids, function (id)
          local card = Fk:getCardById(id)
          return not player:prohibitUse(card) and player:canUse(card, { bypass_times = true })
        end)
        if #ids == 0 then return false end
        room:askToUseRealCard(user, {
          pattern = ids,
          skill_name = shuguo.name,
          prompt = "#doublez__shuguo-use",
          extra_data = {
            bypass_times = true,
            extraUse = true,
            expand_pile = ids,
          }
        })
      end
      fromPlayer = (user ~= player)
    end
  end
})

return shuguo